package com.ly.core.web.listener;

import javax.servlet.ServletContextEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.springframework.web.context.ContextLoaderListener;

import com.ly.core.util.AppUtil;
import com.ly.core.util.XmlUtil;

public class StartupListener extends ContextLoaderListener {
	
	private static Log logger=LogFactory.getLog(StartupListener.class);
	
	public void contextInitialized(ServletContextEvent event) {
		//加载全局菜单
		String filePath = event.getServletContext().getRealPath("/js");
		
		filePath += "/menu.xml";
		
		Document doc = XmlUtil.load(filePath);
		AppUtil.init(event.getServletContext());//初始化函数
		AppUtil.setMenuDocument(doc);
		
		if(doc==null){
			logger.error("error: file is not exist (" + filePath + ")");
		}
		
		super.contextInitialized(event);
	}
}
